<?php namespace app\admin\controller;

class Lunbo extends Common{
    //动作
    public function index(){
    //此处书写代码...
        $lunbo=Db::table('lunbo')->get();
        View::with('lunbo',$lunbo);
//        p($lunbo);die;
        return view();
    }
    //轮播图添加
    public function  lunboadd(){
//        $res=(new Article())->upload();
        if(IS_POST){
            $res=(new \system\model\Lunbo())->lunboadd();
           if($res){
               message('添加成功','index','success');
           }else{
               message('添加失败','back','error');
           }
        }
        return view();
    }

    //轮播图编辑
    public function lunboedit(){
        if(!isset($_GET['lbid'])){
            header('location:index.php?s=admin/lunbo/index');die;
        }
        $lbid=$_GET['lbid'];
        if(IS_POST){
            $res=(new \system\model\Lunbo())->lunboedit($lbid);
            if($res){
                message('修改成功','index','success');
            }else{
                message('修改失败','back','error');
            }
        }
        $lunbo=Db::table('lunbo')->where('lbid',$lbid)->first();
        View::with('lunbo',$lunbo);
        return view();

    }
    //轮播图删除
    public function lunbodel(){
        $lbid=$_GET['lbid'];
        $lunbo=Db::table('lunbo')->where('lbid',$lbid)->first();
        $lb_img=$lunbo['lb_img'];
        if(file_exists($lb_img)){
            unlink($lb_img);
        }
        $res=Db::table('lunbo')->where('lbid',$lbid)->delete();
        if($res){
            message('删除成功','index','success');
        }else{
            message('删除失败','back','error');
        }
    }


}
